'''员工管理模块的 接口对象层'''
import requests

class IhrmEmpCURD(object):
    #添加员工
    @classmethod
    def add_emp(cls,header,json_data):
        url = 'http://ihrm-test.itheima.net/api/sys/user'
        resp = requests.post(url=url, headers=header, json=json_data)
        return resp
    
    #查询员工
    @classmethod
    def query_emp(cls,emp_id,header):
        url = 'http://ihrm-test.itheima.net/api/sys/user'+ emp_id
        resp = requests.get(url=url, headers=header)
        return resp

    #修改员工
    @classmethod
    def modify_emp(cls,emp_id,header,modify_data):
        url = 'http://ihrm-test.itheima.net/api/sys/user'+ emp_id
        resp = requests.put(url=url, headers=header, json=modify_data)
        return resp

    #删除员工
    @classmethod
    def delete_emp(cls,emp_id,header):
        url = 'http://ihrm-test.itheima.net/api/sys/user'+emp_id
        resp = requests.delete(url=url, headers=header)
        return resp

if __name__ == '__main__':
    header = {'Content_type': 'application/json',
              'Authorization': "Bearer cbe8f9cc-5e68-4964-a101-82d70a0b5ccb"} #登录返回后获取的令牌
    json_data = {
        "usename":"业务猪001",
        "mobile":"13978734786",
        "workNumber":"9527"
    }
    resp = IhrmEmpCURD.add_emp(header,json_data)
    print("添加员工：",resp.json())

    emp_id = "14695272901224054784"    #添加员工后获取的id

    resp = IhrmEmpCURD.query_emp(emp_id,header, json_data)
    print("查询员工：", resp.json())

    data = {"usename":"齐天大圣"}
    resp = IhrmEmpCURD.modify_emp(emp_id,header, json_data)
    print("修改员工：", resp.json())

    resp = IhrmEmpCURD.delete_emp(emp_id, header, json_data)
    print("删除员工：", resp.json())

